package com.mogist.hqc.module.product.presenter

import com.mogist.hqc.entitys.BaseResponse
import com.mogist.hqc.entitys.response.CommentListVo
import com.mogist.hqc.entitys.response.ProductDetailVo
import com.mogist.hqc.module.product.contract.ProductDetailContract
import com.mogist.hqc.mvp.HttpDto
import com.mogist.hqc.mvp._PresenterImpl
import com.mogist.hqc.util.Constant
import talex.zsw.basecore.util.JsonTool
import talex.zsw.basecore.util.RegTool
import talex.zsw.basecore.view.dialog.sweetalertdialog.SweetAlertDialog
import talex.zsw.basecore.view.other.RxToast

/**
 * 作用：订单列表 - 详情
 * 作者：赵小白 email:vvtale@gmail.com  
 * 修改人：
 * 修改时间：
 * 修改备注：
 */
class ProductDetailPresenter(view: ProductDetailContract.View) : _PresenterImpl<ProductDetailContract.View, BaseResponse>(
        view), ProductDetailContract.Presenter
{
    override fun requestSuccess(response: BaseResponse, http: HttpDto)
    {
        when (http.url)
        {
            Constant.PRODUCT_DETAIL ->
            {
                if (response.success)
                {
                    mView.disDialog()
                    val vo = JsonTool.getObject(response.content, ProductDetailVo::class.java)
                    mView.bindDetail(vo)
                }
                else
                {
                    mView.showDialog(SweetAlertDialog.ERROR_TYPE,
                                     "获取产品详情失败",
                                     response.message,
                                     "确定",
                                     null,
                                     mView.finishListener,
                                     null)
                }
            }
            Constant.COLLECT_ADD    ->
            {
                if (response.success)
                {
                    RxToast.success("收藏成功")
                    mView?.collectSuccess()
                }
                else
                {
                    if (RegTool.isEmpty(response.message))
                    {
                        RxToast.error("收藏失败，${response.message}")
                    }
                    else
                    {
                        RxToast.error("收藏失败")
                    }
                }
            }
            Constant.PRODUCT_COMMENT ->
            {
                if (response.success)
                {
                    mView.disDialog()
                    val vo = JsonTool.getObject(response.content, CommentListVo::class.java)
                    mView.bindComment(vo)
                }
            }
        }
    }

    override fun requestError(msg: String?, httpDto: HttpDto)
    {
        if (httpDto.url == Constant.COLLECT_ADD)
        {

        }
        else
        {
            super.requestError(msg, httpDto)
        }
    }
}